Declare @DATA_INICIAL DATETIME
Declare @DATA_FINAL DATETIME
Declare @FILIAL as varchar(50)
declare @NUMERO_FISCAL varchar(25)
declare @FILIAL_FILTRO varchar(25)
declare @CODFILIAL varchar(25)
declare @CFILIAL as int
declare @ValorTotalItens numeric(18,2)
declare @VALOR_CONTABIL numeric(18,2)
Declare @CLIFOR as varchar(25)

set @DATA_INICIAL  = '20070601'
set @DATA_FINAL  = '20070624'

DECLARE CUR_INTEGRA_FISCAL CURSOR FOR
SELECT  FILIAL,  CAST(COD_FILIAL AS INT)  FROM FILIAIS where COD_FILIAL <> '' 
and COD_FILIAL > = 1 and COD_FILIAL < 900 and COD_FILIAL <> 800
and REGIAO <> 'INDEFINIDO'       
AND TIPO_FILIAL <> 'INATIVA'    
and COD_FILIAL  = 1


OPEN CUR_INTEGRA_FISCAL

FETCH NEXT FROM CUR_INTEGRA_FISCAL
INTO @FILIAL , @CFILIAL

WHILE @@FETCH_STATUS = 0
   BEGIN
		
	
		EXEC LX_GERA_ENTRADAS_ITEM @DATA_INICIAL, @DATA_FINAL, 'I', '029_SAO JOSE CAMPOS' 
		EXEC LX_GERA_FATURAMENTO_ITEM @DATA_INICIAL, @DATA_FINAL, 'I', '029_SAO JOSE CAMPOS'
		
		FETCH NEXT FROM CUR_INTEGRA_FISCAL
		INTO @CFILIAL , @CFILIAL

END

CLOSE       CUR_INTEGRA_FISCAL
DEALLOCATE  CUR_INTEGRA_FISCAL

EXEC LX_LF_INTEGRA_SAIDA 1,@DATA_INICIAL, @DATA_FINAL, null, NULL, 'I'
EXEC LX_LF_INTEGRA_ENTRADA 1, @DATA_INICIAL, @DATA_FINAL, null, NULL, 'I'

SP_USRHEADBLOCKER

